<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-9-17
 * Time: 上午9:19
 */
include '../common/autoload.php';

include '../common/errBack.php';
include '../common/prodField.php';
include '../common/Prod_Common.php';

$step = abs($_REQUEST['step']);

if($step==2){
    $lid = abs($_POST['lastid']) >0 ? abs($_POST['lastid']) :
        exit('{"res":0,"msg":"请先保存景区信息后再保存门票信息！"}');
    $applyid = abs($_POST['apply_did']);
    $tid = $_POST['tid']>0 ? abs($_POST['tid']): 0;//门票表主键，更新用
    $tobj = new TicketC;
    $res = $tobj->AddTicket($lid,$applyid,$tid);

    //echo json_encode($res);
    if($res['errcode']!==1000) {
        echo json_encode($res);
        exit;
    }
    if(isset($_POST['ticket']) && is_array($_POST['ticket'])) {
        //echo $res['pid'];exit;
        //echo json_encode($_POST['ticket']);exit;
        $soap = SoapInit::GetSoapInside();
        $cre_res = array();
        $upt_res = array();
        $cre_inc = 0;
        $upt_inc = 0;
        foreach($_POST['ticket'] as $key=>$post) {
            if($post['pl'] < $post['pg']) {
                echo  '{"errcode":1007,"msg":"零售价不能小于供货价！"}';
                exit;
            }
            $cr = $tobj->AddPrice($res['pid'], $post,0, $soap);
        }//EOF FOREACH
    }
    //print_r($res);
    echo json_encode($res);
    exit;
}